package com.bian.springboot04thymeleaf.component;

import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;

import java.util.Map;

/**
 * @author bianpengfei
 * @create 2019-01-31 15:43
 **/
@Component
public class MyErrorAttributes extends DefaultErrorAttributes{

    // 返回的map就是页面和json能获取的所有字段
    @Override
    public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) {
        Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
        errorAttributes.put("nihap", "bianpenfei");

        // 我们异常处理器携带的数据
        Map<String, Object> etc = (Map<String, Object>) requestAttributes.getAttribute("etc", 0);
        errorAttributes.put("etc", etc);
        return errorAttributes;
    }
}
